package com.blog.web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.common.core.web.page.TableDataInfo;
import com.blog.common.domain.entity.Tag;
import com.blog.common.domain.vo.ArticleHomeVo;
import com.blog.common.domain.vo.TagVo;
import com.blog.common.mapper.dao.ArticleMapper;
import com.blog.common.mapper.dao.TagMapper;
import com.blog.web.service.TagService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 * 标签 服务实现类
 * </p>
 *
 * @author Valerie
 * @since 2023-02-18
 */
@Service
@RequiredArgsConstructor
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    private final ArticleMapper articleMapper;

    private final TagMapper tagMapper;

    @Override
    public TableDataInfo<TagVo> listTags() {
        List<TagVo> tagVoList = tagMapper.selectTagList();
        return new TableDataInfo<>(tagVoList, tagVoList.size());
    }

    @Override
    public List<ArticleHomeVo> listArticlesByTags(Serializable tagId) {
        return articleMapper.listArticlesByTag(tagId);
    }
}
